package com.example.ecommercedemo.service.impl;

import java.util.Date;
import java.util.List;
import com.example.ecommercedemo.entity.Category;
import com.example.ecommercedemo.mapper.CategoryMapper;
import com.example.ecommercedemo.service.ICategoryService;
import com.example.ecommercedemo.utils.PageResult;
import com.example.ecommercedemo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * categoryService业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@Service
public class CategoryServiceImpl implements ICategoryService
{
    @Autowired
    private CategoryMapper categoryMapper;

//    查询category
    @Override
    public Category selectCategoryByCid(Long cid)
    {
        return categoryMapper.selectCategoryByCid(cid);
    }

//    查询category列表
    @Override
    public PageResult selectCategoryList(Category category, int pageNum, int pageSize)
    {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Category> list=categoryMapper.selectCategoryList(category);//分页数据
        System.out.println(list.size());
        PageInfo<Category> pageInfo=new PageInfo<>(list);
        PageResult pageResult= PageUtils.getPageResult(pageInfo);
        return  pageResult;
    }

    @Override
    public PageResult selectCategoryGoodList(Category category, int pageNum, int pageSize)
    {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Category> list=categoryMapper.selectCategoryGoodList(category);//分页数据
        System.out.println(list.size());
        PageInfo<Category> pageInfo=new PageInfo<>(list);
        PageResult pageResult= PageUtils.getPageResult(pageInfo);
        return  pageResult;
    }


    //    新增category
    @Override
    public int insertCategory(Category category)
    {
//        category.setCreateTime(new Date());
        return categoryMapper.insertCategory(category);
    }

//    修改category
    @Override
    public int updateCategory(Category category)
    {
        category.setUpdateTime(new Date());
        return categoryMapper.updateCategory(category);
    }

//  批量删除category
    @Override
    public int deleteCategoryByCids(Long[] cids)
    {
        return categoryMapper.deleteCategoryByCids(cids);
    }

//    删除category信息
    @Override
    public int deleteCategoryByCid(Long cid)
    {
        return categoryMapper.deleteCategoryByCid(cid);
    }
}
